package com.qfedu.product.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


import com.qfedu.product.dao.productDAO;
import com.qfedu.product.po.Gain;
import com.qfedu.product.po.Product;
import com.qfedu.product.po.SelectInventory;
import com.qfedu.user.po.Client;
import com.qfedu.user.util.DBUtil;

public class productDaoimpl implements productDAO {
	private DBUtil DBUtil = new DBUtil();
	private ResultSet rs = null;
	private int intResult = -1;
	private boolean boolResult = false;
	private Client client=null;
	Product product = null;

	@Override
	public Boolean doEnter(Object[] objects) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Boolean doOuter(Object[] objects) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Product> doSelectSellOne(Object[] objects) {
		List<Product> list = new ArrayList<>();
		String sql = "select * from sell_record where date_format(operation_time,'%Y-%m-%d') between '"+objects[0]+"' and '"+objects[1]+"'";
		System.out.println(sql);
		rs = DBUtil.executeQuery(sql, null);
		try {
			while (rs.next()) {
				product = new Product(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6), rs.getInt(7), rs.getInt(8), rs.getString(9), rs.getString(10));
				list.add(product);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			list = null;
		}
		return list;
	}

	@Override
	public List<Gain> doselectgain(Object[] objects) {
		// TODO Auto-generated method stub
		List<Gain> list=new ArrayList<>();
		Gain gain=null;
		String sql="select date_format(a.operation_time,'%Y-%m-%d') as date,sum(a.production_sum_after-(a.production_num*b.production_cost)) from sell_record a,production_info b where a.production_id=b.production_id  and date_format(a.operation_time,'%Y-%m-%d') between ? and ? group by date_format(a.operation_time,'%Y-%m-%d')";
		rs=DBUtil.executeQuery(sql, objects);
		try {
			while (rs.next()) {
				System.out.println(rs.getString(1));
				System.out.println(rs.getString(2));
				gain=new Gain(rs.getString(1),rs.getString(2));
				list.add(gain);
			}
			for (Gain gain2 : list) {
				System.out.println(gain2);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			list = null;
		}
		return list;
	}

	@Override
	public List<SelectInventory> doselectInventory(Object[] objects) {
		SelectInventory selectInventory = new SelectInventory();
		List<SelectInventory> list = new ArrayList<>();
		String sql = "select a.PRODUCTION_ID,a.PRODUCTION_NAME,b.PRODUCTION_COST,b.PRODUCTION_PRICE,a.PRODUCTION_TYPE,a.PRODUCTION_NUM from inventory a,production_info b where a.PRODUCTION_ID = b.PRODUCTION_ID and (a.PRODUCTION_ID = '"+objects[0]+"' or '"+objects[0]+"' is null) and a.PRODUCTION_NAME like '%"+objects[1]+"%'";
		rs = DBUtil.executeQuery(sql, null);
		try {
			while (rs.next()) {
				selectInventory = new SelectInventory(rs.getString(1), rs.getString(2), rs.getInt(3), rs.getInt(4), rs.getString(5), rs.getInt(6));
				list.add(selectInventory);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			list = null;
		}
		return list;
	}
}
